var myapp=angular.module("app").controller("ActivityCtrl", ["$scope", "$stateParams", "$rootScope", "$interval", "$timeout", "$http", "$state", "utils", "activity", "userInfo", function ($scope, $stateParams, $rootScope, $interval, $timeout, $http, $state, utils, activity, userInfo) {
	/*页面加载完成*/
	$scope.$on('$viewContentLoaded', function (event) {

		setTimeout(function () {
			$(".container").css({
				"min-height": $(window).height(),

			})

		}, 200)
	})

	$scope.activity = activity

	/*01注册活动*/
	if ($state.current.name == "01_register") {
		$scope.Code = $stateParams.userid

		$scope.isgoto = function () {

			if ($rootScope.isapp) {
				wv.go(2)
			} else {
				$state.go("01_register_box", {
					sharecode: $scope.Code,
					channel: 101
				})
			}

		}

	}

	if ($state.current.name == "01_register_box" || $state.current.name == "06_inviteRegister") {
		$scope.MaskShow = false //弹窗关闭显示
		$scope.seqnumber = null //短信流水号
		$scope.error_phone = false //手机号错误提示
		$scope.error_code = false //验证码错误提示
		$scope.user_code = null //user_code
		$scope.channel = $stateParams.channel //渠道

		//获取验证码
		mui(document).on("tap", "#code", function () {
			var _this = $(this)
			/*验证手机号是否注册*/
			$http.get(utils.userSys, {
				params: {
					header: utils.header("070049"),
					body: {
						"phone_number": $scope.phone
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					/*已经注册*/
					$scope.error_phone = true

				} else if (res.header.re_code == "8000") {
					$scope.error_phone = false
					/*未注册*/
					_this.attr("disabled", "disabled")
					var count = 60
					var countTime = $interval(function () {
						count--
						if (count === 0) {
							_this.html("获取验证码")
							_this.removeAttr("disabled")
							$interval.cancel(countTime)
						} else {
							_this.html(count)
						}
					}, 1000)
					/*获取验证码*/
					$http.get(utils.userSys, {
						params: {
							header: utils.header("070052"),
							body: {
								generate_code_type: 0,
								phone_number: $scope.phone,
								user_code: ""
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.seqnumber = res.header.request_seq
						}
					})

				}
			})

		})

		$scope.send = function () {

			/*验证手机号是否注册*/
			$http.get(utils.userSys, {
				params: {
					header: utils.header("070049"),
					body: {
						"phone_number": $scope.phone
					}
				}
			})
				.then(function (res) {
					if (res.header.re_code == "0000") {
						/*已经注册*/
						$scope.error_phone = true
						throw 0
					} else if (res.header.re_code == "8000") {
						/*未注册*/
						$scope.error_phone = false

						return $http.get(utils.userSys, {
							params: {
								header: utils.header("070053"),
								body: {
									generate_seq: $scope.seqnumber,
									verification_code: $scope.code,
									phone_number: $scope.phone
								}
							}
						})

					}
				})
				/*校验验证码*/
				.then(function (res) {
					if (res.header.re_code == "0000") {

						/*提交邀请人信息*/
						return $http.get(utils.LuckSys, {
							params: {
								header: utils.header("190070"),
								body: {
									phone_number_invitee: $scope.phone,
									user_code_inviter: $stateParams.sharecode || "" //推荐人
								}
							}
						})

					} else {
						$scope.error_code = true
						throw 0
					}

				})
				.then(function (res) {
					if (res.header.re_code == "0000") {
						return $http.get(utils.userSys, {
							params: {
								header: utils.header("070054"),
								body: {
									download: $scope.channel || 101,
									phone_id: "",
									phone_number: $scope.phone,
									register_ip: "",
									register_time: ""
								}
							}
						})
					} else {
						throw 0
					}
				})

				/*注册*/
				.then(function (res) {
					if (res.header.re_code == "0000") {
						$scope.user_code = res.body.user_code
						return $http.get(utils.userSys, {
							params: {
								header: utils.header("070055"),
								body: {
									login_type: "0",
									new_password: "",
									old_password: md5($scope.pwd),
									set_type: "0",
									user_code: $scope.user_code,
									user_type: "4",
									fingerprint_password: "",
									gesture_password: "",
									third_bind_id: "",
									third_platform_id: ""
								}
							}
						})
					} else {
						throw 0
					}
				})
				/*设置密码*/
				.then(function (res) {
					if (res.header.re_code == "0000") {
						$scope.MaskShow = true
					}
				})
				.catch(function (reason) {

				})

		}
	}

	/*02风险测评*/
	if ($state.current.name == "02_Evaluation") {
		var userid = activity.getUser_code() //获取用户id
		//		$scope.tabIndex = 0 //页数索引
		$scope.evaluationTile = null //评测类型
		$scope.evaluationInfo = null //评测内容
		$scope.arr = []
		var num = 0 //分数
		$scope.isfirstEv = false;
		//获取题目
		$http.get("json/Evaluation.json", {}).then(function (res) {
			$scope.EvaluationList = res
			$scope.arr = new Array(res.length) //创建数组
		})

		/*已经评测*/
		if (userid) {
			/*获取用户评测信息*/
			$http.post(utils.activiSys + "/risk/user_risk/user_result_list.do", {}, {
				params: {
					userId: userid
				}
			}).then(function (res) {
				if (res.list.length != 0) {
					sum(res.list[0].score)
					$scope.tabIndex = 11;
				} else {
					$scope.tabIndex = 0
					$scope.isfirstEv = true;
				}
			})
		} else {
			$scope.tabIndex = 0
		}

		//开始评测
		$scope.starEvalua = function () {
			if (!userid) {
				utils.msg("请先登录!")
				return
			}
			$http.get(utils.userSys, {
				params: {
					header: utils.header("070117"),
					body: {
						check_type: "0",
						phone_number: "",
						user_code: userid,
						phone_type: ""
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					if (res.body.is_real_name == 0) {
						utils.msg("请先实名！")
						return
					}
					/*获取用户评测信息*/
					$http.post(utils.activiSys + "/risk/user_risk/user_result_list.do", {}, {
						params: {
							userId: userid
						}
					}).then(function (res) {
						if (res.list.length == 0) {
							$scope.tabIndex = $scope.tabIndex + 1
							$scope.isfirstEv = true;
						} else {
							sum(res.list[0].score)
							$scope.tabIndex = 11
						}
					})

				}
			})

		}

		//确定
		$scope.Submit = function () {
			activity.web_close()
		}

		/*测评*/
		$scope.send = function () {
			if ($scope.tabIndex == 10) {
				angular.forEach($scope.arr, function (value, index) {
					num += parseInt(value.num)
				})
				sum(num)
				var temps = []
				angular.forEach($scope.arr, function (value, index) {
					temps.push("{'qSerial': " + (index * 1 + 1) + ",'aSerial': " + value.serial + "}")
				})
				$http.post(utils.activiSys + "/risk/user_risk/answer.do", {}, {
					params: {
						userId: userid,
						score: num,
						result: $scope.evaluationTile,
						answers: "[" + temps.toString() + "]"
					}
				}).then(function (res) {
					if (res.resCode == "0000") {
						$scope.tabIndex = $scope.tabIndex + 1
						if ($scope.isfirstEv) {
							$http.get(utils.integralSys, {
								params: {
									header: utils.header("300308"),
									body: {
										task: "4",
										userCode: activity.getSoloCode()
									}
								}
							}).then(function () {

							})
						}
					} else {
						utils.msg("提交失败!")
					}
				})
			}
		}
		/*点击点选框*/
		$scope.nexts = function () {
			// alert("123")
			if ($scope.tabIndex < 10) {

				$scope.tabIndex = $scope.tabIndex + 1

			}
		}
		/*重新评测*/
		$scope.resets = function () {
			$scope.tabIndex = 1
			num = 0
			$scope.arr = new Array($scope.EvaluationList.length)
		}
		/*计算总分*/
		function sum(num) {
			if (num >= 0 && num <= 60) {
				$scope.evaluationTile = "保守型"
				$scope.evaluationInfo = "您对风险损失比较敏感，投资时谨慎小心，更看重资金的安全性。"
			} else if (num > 60 && num <= 70) {
				$scope.evaluationTile = "稳健型"
				$scope.evaluationInfo = "您对风险损失较为谨慎，投资时你注重资金的安全性，追求稳健的收益回报。"
			} else if (num > 70 && num <= 80) {
				$scope.evaluationTile = "平衡型"
				$scope.evaluationInfo = "您对风险有着清晰的认识，投资时你注重在“风险最小化”和“收益最大化”之间寻找最优平衡。"
			} else if (num > 80 && num <= 90) {
				$scope.evaluationTile = "成长型"
				$scope.evaluationInfo = "您的风险承受能力较高，投资时您较为积极，乐于尝试，愿意承担一定的风险来博取较高收益。"
			} else if (num > 90 && num <= 100) {
				$scope.evaluationTile = "进取型"
				$scope.evaluationInfo = "您风险承受能力高，投资时大胆激进，勇于尝试，追求最大的投资回报，是资深的投资者。"
			}
		}

	}

	/*03测试关键字*/
	if ($state.current.name == "03_Keyword") {

		if ($rootScope.isapp) {
			Woption = {
				'title': '震惊！我的2018年关键词竟是这个？',
				'content': '震惊！我的2018年关键词竟是这个？',
				'icon': "http://www.beikbank.com/image/58px.png",
				'linkUrl': window.location.href,
				'code': '1',
			}
			wv.share(JSON.stringify(Woption))
		}

		var userid = activity.getUser_code() //获取用户id
		var offon = false //抽奖开关
		$scope.Prize = 0
		/*获取抽奖用户信息*/
		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190050"),
				body: {
					count: 10
				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {

				$scope.cjList = res.body

			}
		})

		/*获取抽奖次数*/
		if (userid) {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190040"),
					body: {
						user_code: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					if (res.body.limit_count == 1) {
						offon = true
					} else {
						activity.Prize = res.body.bonus_no
						$scope.Prize = res.body.bonus_no //已经抽过奖设置奖品

						$(".FlopBox li").eq(res.body.draw_index * 1 - 1).html("<img src='image/activity/03_Keyword/0" + $scope.Prize + ".png'/>")

					}

				}
			})
		}
		/*开始抽奖*/
		$(".FlopBox li").on("click", function () {
			var index = $(this).index()
			var _this = $(this)
			if (!userid) {
				if ($rootScope.isapp) {
					return utils.msg("请先登录！")
				} else {
					mui.confirm('请登录赚啦APP参与活动', ' ', ['取消', '下载'], function (e) {
						if (e.index === 1) {
							return activity.download()
						}
					}, 'div')
					return
				}

			}

			if (offon) {
				$http.get(utils.LuckSys, {
					params: {
						header: utils.header("190060"),
						body: {
							user_code: userid,
							draw_index: index + 1
						}
					}
				}).then(function (res) {
					if (res.header.re_code == "0000") {
						_this.addClass("star").siblings().unbind()
						var timeer = $timeout(function () {
							$timeout.cancel(timeer)
							activity.Prize = res.body.bonus_no //设置活动服务里奖品
							$scope.Prize = activity.Prize
							$state.go("03_Keyword_box")
						}, 2000)
					}

				})
			} else {

				utils.msg("您没有抽奖次数或您已抽过奖！")
			}

		})

	}

	/*显示关键字*/
	if ($state.current.name == "03_Keyword_box") {
		$scope.Prize = activity.Prize
		if ($rootScope.isapp) {
			Woption = {
				'title': '震惊！我的2018年关键词竟是这个？',
				'content': '测完还能领取最高188元红包，哦耶！',
				'icon': "http://www.beikbank.com/image/58px.png",
				'linkUrl': window.location.href,
				'code': '0',
			}
			wv.share(JSON.stringify(Woption))
		}
	}

	/*04邀请活动*/
	if ($state.current.name == "04_Share") {
		var userid = activity.getUser_code() //获取用户id
		$scope.shareListShow = false
		$scope.isListshow = function () {
			if (userid) {
				$scope.shareListShow = true
			} else {
				return utils.msg("请先登录!")
			}

		}

		//阻止滚动穿透
		$(".shareList").on("touchmove", function (event) {
			event.preventDefault();
		});

		if (userid) {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190080"),
					body: {
						user_code: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.shareListData = res.body
				}

			})
		}

		$scope.shares = function () {
			if (!userid) {
				return utils.msg("请先登录!")
			}

			Woption = {
				'title': '我在赚啦给你送了888元红包，快来免费领取！',
				'content': '注册即送888元红包，更享新手标15%超高收益',
				'icon': "http://www.beikbank.com/image/58px.png",
				'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/01_register?uk=SK" + userid,
				'code': '0',
			}
			wv.shareWithShareData(JSON.stringify(Woption))

		}

	}

	/*05——38祝福*/
	if ($state.current.name == "05_38") {
		$scope.wdhbShow = false //我的红包
		$scope.hdgzShow = false //活动规则
		$scope.to = null //祝福对象
		$scope.froms = null //祝福人
		var userid = activity.getUser_code() //获取用户id

		/*获取祝福总数*/
		function getLuck() {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190120"),
					body: {

					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.wishList = res.body
				}
			})
		}
		getLuck()

		/*跳转登录*/
		function islogin() {
			if ($rootScope.isapp) { //如果在APP打开直接跳登录
				wv.go(2) //跳登录
				return
			} else { //否则跳下载
				if (!userid) {
					utils.msg("请登录APP参与活动!", 1, function () {
						$scope.activity.download() //跳下载
					})
				}
				return
			}
		}

		/*查看红包*/
		$scope.lock = function () {
			if (!userid) {
				islogin()
				return
			}

			if ($scope.Surplus.limit_count == 3) {
				utils.msg("请先发送祝福!")
				return
			}

			$scope.wdhbShow = true
		}

		/*送祝福*/
		$scope.giveLuck = function (index) {
			/*是否登录*/
			if (!userid) {
				islogin()
				return
			}

			/*发送祝福*/
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190110"),
					body: {
						user_code: userid,
						wish_from: $scope.froms || $scope.Surplus.wish_from,
						wish_index: index,
						wish_to: $scope.to || $scope.Surplus.wish_to
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					utils.msg("祝福已送上!")
					sendLuck()
					getLuck()

				}
			})

		}

		/*我的祝福*/
		if (userid) {
			sendLuck()
		}
		$scope.Surplus = {
			result: [],
			limit_count: 3
		}

		function sendLuck() {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190090"),
					body: {
						user_code: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.Surplus = res.body //获取剩余

					for (var i = 0; i < $scope.Surplus.result.length; i++) {
						$(".zf_list li").eq($scope.Surplus.result[i].wish_index - 1).find("button").remove()
						$(".zf_list li").eq($scope.Surplus.result[i].wish_index - 1).append('<button style="background:#b3b3b3">已送祝福</button>')
					}

				}
			})

			/*获取红包*/
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190130"),
					body: {
						user_code: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.hongbaoList = res.body
				}

			})

		}
		//跳转
		$scope.sendHb = function () {
			if (!userid) {
				islogin()
				return
			}
			if ($scope.Surplus.limit_count == 3) {
				utils.msg("请先发送祝福!")
				return
			}
			if ($scope.Surplus.limit_count < 3) {
				$state.go("05_38_fx")
			}

		}

		/*获取祝福*/
		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190100"),
				body: {
					count: 10
				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {
				$scope.luckS = res.body
				var mySwiper1 = new Swiper('.swiper-container', {
					autoplay: 1,
					speed: 4000,
					loop: true,
					freeMode: true,
					slidesPerView: 1,
					slidesPerGroup: 1,
					autoplayDisableOnInteraction: false,
					observer: true,
					observeParents: true,
				});
			}
		})

	}

	/*红包分享*/
	if ($state.current.name == "05_38_fx") {
		var userid = activity.getUser_code()
		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190090"),
				body: {
					user_code: userid
				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {
				$scope.Surplus = res.body //获取剩余
			}
		})

		/* 在APP内关闭右上角按钮*/
		if ($rootScope.isapp) {
			if (mui.os.ios) {
				$scope.activity.right_close()
			} else {
				Woption = {
					'title': '3.8女神节',
					'content': '给女神送祝福还能拿TF口红领红包',
					'icon': "https://www.zhuanlalicai.com/images/58px.png",
					'linkUrl': window.location.href,
					'code': '0',
				}
				wv.share(JSON.stringify(Woption))
			}
		}

	}

	/*长期邀友07*/
	if ($state.current.name == "07_InviteFriends") {
		$scope.showMask = false //二维码
		$scope.showGz = false //活动规则
		$scope.showYq = false //邀请记录
		var userid = activity.getUser_code()
		var userid2 = activity.getUser_code2()

		$scope.esc = function () {
			$scope.showMask = false
		}

		$(".ercode").on("touchmove", function (e) {
			e.preventDefault();
		})

		var qr = new QRCode(document.getElementById("qrcode"), {
			text: window.location.origin + window.location.pathname + "#!" + "/activity/01_register/" + userid2,
			render: "canvas",
			width: 250,
			height: 250,
			colorDark: "#000",
			colorLight: "#fff",
			correctLevel: QRCode.CorrectLevel.H
		})

		$scope.getCode = function () {
			if ($rootScope.isapp) {
				if (userid) {

					$scope.showMask = true
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}
		}

		$scope.getYqList = function () {

			if ($rootScope.isapp) {
				if (userid) {
					$http.get(utils.LuckSys, {
						params: {
							header: utils.header("190170"),
							body: {
								userCode: userid
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.friendsData = res.body
						}
					})
					$scope.showYq = true
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}

		}

		$scope.share = function () {
			if ($rootScope.isapp) {
				if (userid) {
					Woption = {
						'title': '好友邀你赚钱啦！',
						'content': '上赚啦，赚一点，新手2.5%和1.5%加息券等你来拿~',
						'icon': "https://www.zhuanlalicai.com/images/58px.png",
						'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/01_register",
						'code': '1',
					}
					wv.shareWithShareData(JSON.stringify(Woption))
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}

		}

		if ($rootScope.isapp) {
			$scope.activity.right_close()
		}

	}

	/*518邀友活动*/
	if ($state.current.name == "08_518") {
		$scope.showMask = false //二维码
		$scope.showGz = false //活动规则
		$scope.showYq = false //邀请记录
		var userid = activity.getUser_code()
		var userid2 = activity.getUser_code2()

		$scope.esc = function () {
			$scope.showMask = false
		}

		$(".ercode").on("touchmove", function (e) {
			e.preventDefault();
		})

		/*二维码*/
		var qr = new QRCode(document.getElementById("qrcode"), {
			text: window.location.origin + window.location.pathname + "#!" + "/activity/01_register/" + userid2,
			render: "canvas",
			width: 250,
			height: 250,
			colorDark: "#000",
			colorLight: "#fff",
			correctLevel: QRCode.CorrectLevel.H
		})

		/*当面邀友*/
		$scope.getCode = function () {
			$scope.showMask = true
			if ($rootScope.isapp) {
				if (userid) {
					$scope.showMask = true
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}
		}

		$scope.getYqList = function () {

			if ($rootScope.isapp) {
				if (userid) {
					$http.get(utils.LuckSys, {
						params: {
							header: utils.header("190170"),
							body: {
								userCode: userid
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.friendsData = res.body
							$scope.showYq = true
						}
					})

				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}

		}

		/*分享邀友*/
		$scope.share = function () {
			if ($rootScope.isapp) {
				if (userid) {
					Woption = {
						'title': '好友邀你赚钱啦！',
						'content': '上赚啦，赚一点，新手2.5%和1.5%加息券等你来拿~',
						'icon': "https://www.zhuanlalicai.com/images/58px.png",
						'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/01_register",
						'code': '1',
					}
					wv.shareWithShareData(JSON.stringify(Woption))
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}
		}

		if ($rootScope.isapp) {
			$scope.activity.right_close()
		}

	}

	/*10七夕活动*/
	if ($state.current.name == "10_Julyseven") {
		var userid = activity.getUser_code()
		/* var userid = "1122" */
		$scope.count = 0
		$scope.jpMask = false
		$scope.smMask = false
		$scope.wdjpMask = false
		$scope.cjOffon = true
		$scope.go = function () {
			if ($rootScope.isapp) { //如果在APP打开
				wv.go(1) //跳产品
				return
			} else { //否则跳下载
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
				return
			}
		}

		if (userid) {

			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190200"),
					body: {
						userCode: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.count = res.body.remainChance
					$scope.prizeList = res.body.prizeList
					$scope.prizeList[0].sort = 0
					$scope.prizeList[1].sort = 3
					$scope.prizeList[2].sort = 7
					$scope.prizeList[3].sort = 5
					$scope.prizeList[4].sort = 2
					$scope.prizeList[5].sort = 4
					$scope.prizeList[6].sort = 9
					$scope.prizeList[7].sort = 8
					$scope.prizeList[8].sort = 1
					$scope.prizeList[9].sort = 6
				}
			})
		} else {
			utils.msg("请先登录!", 1, function () {
			})
			return
		}


		mui(document).on("tap", "#zhuan_btn", function () {

			if ($rootScope.isapp) {
				$scope.zhuan()
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}


		})



		$scope.zhuan = function () {
			if (userid) { //如果在APP打开
				if ($scope.cjOffon) {
					$http.get(utils.LuckSys, {
						params: {
							header: utils.header("190190"),
							body: {
								userCode: userid
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.cjOffon = false
							$scope.count = res.body.remainChance//设置剩余次数
							angular.forEach($scope.prizeList, function (value, index) {
								if (value.id == res.body.prizeId) {
									zhuan("zhuan_bg", 5000, 3600 - value.sort * 36, function () {
										$scope.jpMask = true
										$scope.prizeName = value.prizeName
										$scope.$apply()
										$scope.cjOffon = true

									})
								}
							})

						}
					})

				}
			} else {
				utils.msg("请登录!", 1, function () {

				})

			}

		}


		$scope.getjpList = function () {
			if (userid) {

				$http.get(utils.LuckSys, {
					params: {
						header: utils.header("190210"),
						body: {
							userCode: userid
						}
					}
				}).then(function (res) {
					if (res.header.re_code == "0000") {
						$scope.jpList = res.body
						$scope.wdjpMask = true
					}
				})


			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
				return
			}
		}


		if ($rootScope.isapp) {
			Woption = {
				'title': '这个七夕赚啦用超值好礼、现金红包独宠你！',
				'content': 'DW情侣表、1000元京东卡、野兽派礼物、现金红包纷纷砸向你',
				'icon': "http://www.beikbank.com/image/58px.png",
				'linkUrl': window.location.href + "?aa=",
				'code': '1',
			}
			wv.share(JSON.stringify(Woption))
		}


		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190224"),
				body: {

				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {
				var mySwiper1 = new Swiper('.swiper-container', {
					autoplay: 1,
					speed: 4000,
					loop: true,
					freeMode: true,
					slidesPerView: 1,
					slidesPerGroup: 1,
					autoplayDisableOnInteraction: false,
					observer: true,
					observeParents: true,
				});
				$scope.luckS = res.body
			}
		})


		var offon = true
		function zhuan(ele, ms, deg, func) {
			if (offon) {
				offon = false
				var obj = document.getElementById(ele);
				function donghua(call) {
					$(obj).removeAttr("style")
					setTimeout(function () {
						call()
					}, 100)
				}
				donghua(function () {
					$(obj).css({
						"transition": "all " + ms + "ms ease-out",
						"-webkit-transition": "all " + ms + "ms ease-out",
						"transform": "rotate(" + deg + "deg)",
						"-webkit-transform": "rotate(" + deg + "deg)"
					})
				})

				setTimeout(function () {
					offon = true
					func()
				}, ms);
			}

		}




	}

	/* 11邀友奖励升级 */
	if ($state.current.name == "11_InviteFriendsUp") {

		$scope.showMask = false //二维码
		$scope.showGz = false //活动规则
		$scope.showYq = false //邀请记录
		var userid = activity.getUser_code()
		var userid2 = activity.getUser_code2()

		$scope.esc = function () {
			$scope.showMask = false
		}

		$(".ercode").on("touchmove", function (e) {
			e.preventDefault();
		})



		var qr = new QRCode(document.getElementById("qrcode"), {
			text: window.location.origin + window.location.pathname + "#!" + "/activity/01_register/" + userid2,
			render: "canvas",
			width: 250,
			height: 250,
			colorDark: "#000",
			colorLight: "#fff",
			correctLevel: QRCode.CorrectLevel.H
		})

		$scope.getCode = function () {
			if ($rootScope.isapp) {
				if (userid) {

					$scope.showMask = true
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}
		}

		$scope.getYqList = function () {

			if ($rootScope.isapp) {
				if (userid) {
					$http.get(utils.LuckSys, {
						params: {
							header: utils.header("190170"),
							body: {
								userCode: userid
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.friendsData = res.body
						}
					})
					$scope.showYq = true
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}

		}

		$scope.share = function () {
			if ($rootScope.isapp) {
				if (userid) {
					Woption = {
						'title': '好友邀你赚钱啦！',
						'content': '上赚啦，赚一点，新手2.5%和1.5%加息券等你来拿~',
						'icon': "https://www.zhuanlalicai.com/images/58px.png",
						'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/01_register/" + userid2,
						'code': '1',
					}
					wv.shareWithShareData(JSON.stringify(Woption))
				} else {
					utils.msg("请先登录!")
				}
			} else {
				utils.msg("请登录APP参与活动!", 1, function () {
					$scope.activity.download() //跳下载
				})
			}

		}

		if ($rootScope.isapp) {
			$scope.activity.right_close()
		}


	}

	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return unescape(r[2]);
		return null;
	}


	/* 12助力加息 */
	if ($state.current.name == "12_zhuli") {
		var userid = activity.getUser_code()
		$scope.hdgzShow = false//活动规则弹窗

		$scope.goview = function () {//没有活动
			if ($scope.isapp) {
				wv.go(1)
			} else {
				$state.go("all")
			}
		}

		if (userid) {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190233"),
					body: {
						userCode: userid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.listInfo = res.body
				}
			})
		} else {
			utils.msg("未登录!")
		}


	}

	/* 12助力详情 */
	if ($state.current.name == "12_details") {
		$scope.hdgzShow = false//活动规则弹窗
		var userid = activity.getUser_code()
		var userphone = activity.getUser_phone()
		$scope.chanceRecordId = Number($stateParams.chanceRecordId)
		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190229"),
				body: {
					chanceRecordId: $scope.chanceRecordId,
					openid: userid
				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {
				$http.get(utils.LuckSys, {
					params: {
						header: utils.header("190230"),
						body: {
							chanceRecordId: $scope.chanceRecordId,
						}
					}
				}).then(function (res) {
					if (res.header.re_code == "0000") {
						$scope.detailsData = res.body
						if ($scope.isapp) {
							Woption = {
								'title': '我在赚啦抢3.5%的加息券，就差你的一臂之力啦！',
								'content': '盆友，我是真的真的需要你~',
								'div': $scope.detailsData.list.length == 1 ? '<p style="text-align:center;color:#fff;font-size:20px;margin:0">您已助力<font color="#FF5C26" style="font-size:35px">' + $scope.detailsData.hasIncrValueOrRateStr + '</font>啦</p><p style="text-align:center;margin:0;font-size:20px;color:#fff">分享给好友 可以多砍一刀哦</p>' : '',
								'icon': "https://www.zhuanlalicai.com/images/58px.png",
								'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/12_share/" + userid + "/" + $scope.chanceRecordId,
								'code': '1',
							}
							if ($scope.detailsData.list.length == 1) {
								wv.shareWithShareData(JSON.stringify(Woption))
							}

						}
					}
				})

			}
		})

		/* 去分享 */
		$scope.share = function () {
			wv.shareWithShareData(JSON.stringify(Woption))
		}

		/* 去领取 */
		$scope.lingqu = function () {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190232"),
					body: {
						chanceRecordId: $scope.chanceRecordId
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					utils.msg("领取成功!")
					$http.get(utils.LuckSys, {
						params: {
							header: utils.header("190230"),
							body: {
								chanceRecordId: $scope.chanceRecordId,
							}
						}
					}).then(function (res) {
						if (res.header.re_code == "0000") {
							$scope.detailsData = res.body
						}
					})
				}
			})
		}



	}

	/* 12助力分享 */
	if ($state.current.name == "12_share") {
		$scope.hdgzShow = false//活动规则弹窗
		$scope.iszhuli = false//是否助力过
		var userid = $stateParams.userid
		var chanceRecordId = Number($stateParams.chanceRecordId)

		/* 第一次授权获取微信code */
		var code = getUrlParam("code")
		if (code) {
			if (!localStorage.openid) {
				$http.get(utils.LuckSys, {
					params: {
						header: utils.header("190236"),
						body: {
							"code": code
						}
					}
				}).then(function (res) {
					if (res.header.re_code == "0000") {
						localStorage.openid = res.body.openid
						getInfo()
					}
				})
			} else {
				getInfo()
			}

		} else {
			if (!localStorage.openid) {
				return location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx845ef52f84d372d7&redirect_uri=' + escape(location.href) + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
			} else {
				getInfo()
			}
		}



		// 获取邀请信息
		function getInfo() {
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190230"),
					body: {
						chanceRecordId: chanceRecordId,
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					$scope.detailsData = res.body
				}
			})

			/* 获取该用户是否助力过 */
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190239"),
					body: {
						chanceId: chanceRecordId,
						openid: localStorage.openid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					if (res.body.flag == 1) {
						$scope.iszhuli = true
					}
				}
			})
		}

		$scope.goregister = function () {
			$state.go("01_register", {
				userid: userid
			})
		}

		$http.get(utils.LuckSys, {
			params: {
				header: utils.header("190238"),
				body: {
					url: location.href.split('#')[0]
				}
			}
		}).then(function (res) {
			if (res.header.re_code == "0000") {
				console.log(res.body)
				wx.config({
					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
					appId: res.body.appId, // 必填，公众号的唯一标识
					timestamp: res.body.timestamp, // 必填，生成签名的时间戳
					nonceStr: res.body.nonceStr, // 必填，生成签名的随机串
					signature: res.body.signature,// 必填，签名
					jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填，需要使用的JS接口列表
				});
			}

		})

		wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
			//设置分享给朋友内容
			wx.onMenuShareAppMessage({
				title: '我在赚啦抢3.5%的加息券，就差你的一臂之力啦！', // 分享标题
				desc: '盆友，我是真的真的需要你~', // 分享描述
				link: location.origin + location.pathname + location.hash, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: 'https://www.zhuanlalicai.com/images/58px.png', // 分享图标
			}, function (res) {
				//这里是回调函数 
			});

			// 设置分享到朋友圈内容
			wx.onMenuShareTimeline({
				title: '我在赚啦抢3.5%的加息券，就差你的一臂之力啦！', // 分享标题
				link: location.origin + location.pathname + location.hash, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
				imgUrl: 'https://www.zhuanlalicai.com/images/58px.png', // 分享图标
			}, function (res) {
				//这里是回调函数 
			});

		});


		$scope.zhuli = function () {
			/* 帮好友助力 */
			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190229"),
					body: {
						chanceRecordId: chanceRecordId,
						openid: localStorage.openid
					}
				}
			}).then(function (res) {
				if (res.header.re_code == "0000") {
					if (res.header.re_msg == "24") {
						mui.alert("一天内只能为同一好友助力1次哦", " ", "我也免费领！", function () {
							$state.go("01_register", {
								userid: userid
							})
						}, "div")
					} else {
						utils.msg("您已帮好友助力成功!", 3)
						getInfo()
					}


				}
			})

		}

	}

	if ($state.current.name == "13_pashan") {
		$scope.showMask = false

		if ($(window).height() > 736) {
			$scope.imgurl = "image/activity/13_pashan/bg1.jpg"
		} else {
			$scope.imgurl = "image/activity/13_pashan/bg.jpg"
		}

		$scope.send = function () {

            if(!/^1\d{10}$/.test($scope.phoneNumber)){
                  return utils.msg("手机号码格式不正确!")
			}


			$http.get(utils.LuckSys, {
				params: {
					header: utils.header("190240"),
					body: {
						phoneNumber: $scope.phoneNumber
					}
				}
			}).then(function (res) {
				console.log(res)
				if (res.header.re_code == "0000") {
					$scope.showMask = true
					$scope.hongbaoText=res.body.prizeName
				}
			})

		}

	}
	if($state.current.name == "14_diyRedPacket"){
		
		var tt="",userid = activity.getUser_code(), //获取用户id
			actId="";//活动id
		$scope.diyMoney="";//用户输入的值
		$scope.redPacket={
			limitCount:"",//可定制次数
			maxAmount:"",//可定制最大金额
			minAmount:"",//可定制最小金额
			couponType:"",//优惠券类型
			yhqName:"",//优惠券名称
			rewards:"",//奖励规则
			result:"",//根据定制金额得到的优惠券数据
			id:"",//优惠券id
			minProductTime:"",//最小项目期限
			incrRateOrAmount:"",//优惠券具体的奖励金额或利息
			isact:false,//是否可以领取奖励
			font:false,//设置字体
			succ:false,//领取成功弹窗
			gc_chance:false,//没有领取机会弹窗
			errContent:"",
			errShow:false
		}
		//初始加载数据
		$http.get(utils.LuckSys,{
			params:{
				header:utils.header('190241'),
				body:{
					userCode:userid
				}
			}
		}).then(function(res) {
			if(res.header.re_code=="0000"){
				if(!userid){
					var ab=document.getElementById("amount")
					res.body.limitCount="?"
					ab.setAttribute("readOnly", true);
					ab.onclick=function(){
						utils.msg(res.header.re_msg)
					}
					utils.msg(res.header.re_msg)
				}
				actId = res.body.actId
				$scope.redPacket.limitCount=res.body.limitCount
				$scope.redPacket.maxAmount=res.body.maxAmount
				$scope.redPacket.minAmount=res.body.minAmount
				$scope.redPacket.yhqName=res.body.couponType==3?
					"优惠券":(res.body.couponType==1?"红包":"体验金")
				$scope.redPacket.couponType=res.body.couponType
				$scope.redPacket.rewards=res.body.rewards
				
			}
			
		})
		$scope.gc_clear=function(type){
			// $scope.diyMoney=""
			if(type==1){
				$scope.redPacket.errContent="投资金额不能为空"
			}else if(type==2){
				$scope.redPacket.errContent="投资金额必须≤"+$scope.redPacket.maxAmount
			}else if(type==3){
				$scope.redPacket.errContent="投资金额必须是"+$scope.redPacket.minAmount+"整数倍"
			}else if(type==4){
				$("#amount").css('border-color','#ff2805')
				$scope.redPacket.errContent="投资金额不能为空"
				$scope.redPacket.errShow=true
				return 
			}
			$scope.redPacket.errShow=true
			$scope.redPacket.result=$scope.redPacket.rewards
			$scope.$apply()
			$(".lists").removeClass('gc_select')
			$("#amount").css('border-color','#ff2805')
		}
		$scope.touchmove=function(){
			document.getElementById('amount').blur()
			document.removeEventListener('touchmove',$scope.touchmove)
		}
		//监听输入框的值  延时请求后端数据
		$scope.$watch('diyMoney',function(newValue, oldValue){
			if ($scope.diyMoney != oldValue){
				//当value改变时执行的代码
	
				$scope.redPacket.isact=false

				clearTimeout(tt)

				tt=setTimeout(function(){
					//safar在input聚焦唤起手机键盘后滑动内容键盘不会收起，处理
					document.addEventListener('touchmove',$scope.touchmove,false)
					$(".lists").removeClass('gc_select')
					if($scope.diyMoney==""){
						return $scope.gc_clear(1)
					}

					if($scope.redPacket.limitCount<=0){
						document.getElementById('amount').blur()
						$scope.redPacket.gc_chance=true;
					}

					if($scope.diyMoney>$scope.redPacket.maxAmount){
						$scope.gc_clear(2)
						
						return 
					}
					if($scope.diyMoney%$scope.redPacket.minAmount!=0){
						$scope.gc_clear(3)
						return 
					}
					$scope.redPacket.errShow=false
					//查询用户输入金额可定制的优惠券范围
					$http.get(utils.LuckSys,{
						params:{
							header:utils.header('190242'),
							body:{
								userCode:userid,
								actId:actId,
								amount:newValue
							}
						}
					}).then(function(res) {
						if(res.header.re_code=="0000"){
							$scope.redPacket.result=res.body.rewards
							var reArr=res.body.rewards
							var pwidth=$(".container").width();
							if(pwidth<330 && reArr[3].incrRateOrAmount>=100){
								$scope.redPacket.font=true;
							}
							$("#amount").css('border-color','rgba(0,0,0,.2)')
						}
					})
				},600)
			}
		})
		//选择红包
		$scope.hbSelect=function(id,minProductTime,index,obj){

			
			if($scope.diyMoney==""){
				$scope.gc_clear(4);
			}
			if($scope.redPacket.errShow){
				return
			}
			if($scope.redPacket.limitCount<=0){
				return
			}else{
				$scope.redPacket.isact=true
			}
			
			$scope.redPacket.id=id;

			var result=$scope.redPacket.result
			for(var i=0;i<result.length;i++){
				if(id==result[i].id){
					$scope.redPacket.incrRateOrAmount=result[i].incrRateOrAmount
					break
				}
			}
			$scope.redPacket.minProductTime=minProductTime;
			if($(obj.target).is('div')){
				$(obj.target).addClass('gc_select').siblings().removeClass('gc_select')
			}else{
				var abc=$(obj.target).closest('.lists')
				abc.addClass('gc_select').siblings().removeClass('gc_select')
			}
			
		}
		$scope.gc_go=function(){
			if ($scope.isapp) {
				wv.go(1)
			} else {
				$state.go("all")
			}
		}

		//发送优惠券并弹窗提示
		$scope.sendRed=function(){
			if(!$scope.redPacket.isact){
				return
			}
			$scope.redPacket.isact=false;
			$http.get(utils.LuckSys,{
				params:{
					header:utils.header('190243'),
					body:{
						userCode:userid,
						actId:actId,
						amount:$scope.diyMoney,
						id:$scope.redPacket.id,
						incrRateOrAmount:$scope.redPacket.incrRateOrAmount,
						minProductTime:$scope.redPacket.minProductTime,
						couponType:$scope.redPacket.couponType

					}
				}
			}).then(function(res) {
				if(res.header.re_code=="0000"){
					$scope.redPacket.limitCount-=1
					$scope.redPacket.succ=true;
					if($scope.redPacket.limitCount<=0){
						$scope.redPacket.isact=false
						$scope.redPacket.result=$scope.redPacket.rewards
						$(".lists").removeClass('gc_select')
					}else{
						$scope.redPacket.isact=true
					}
				}
				
			})	
		}
		if ($scope.isapp) {
			Woption = {
				'title': '国庆红包，专属定制',
				'content': '最高800元等你来领哦',
				'icon': "https://www.zhuanlalicai.com/images/58px.png",
				'linkUrl': window.location.origin + window.location.pathname + "#!" + "/activity/14_share",
				'code': '1',
			}
			wv.share(JSON.stringify(Woption))
			
		}
	}
	if($state.current.name == "14_share"){
		$scope.gc_download=function(){
			activity.download()
		}
	}

}])